/**
 * 2018-09-08 00:53:53
 */
package com.cdxy.config;

import com.cdxy.model.dto.base.exception.GdaException;
import com.cdxy.model.dto.base.resp.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author Esion 全局异常捕获
 */
@ControllerAdvice
public class GlobalDefaultExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalDefaultExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ApiResponse<String> defaultExceptionHandler(GdaException e) {
        e.printStackTrace();
        ;
        log.info("***************异常开始***************");
        log.error(e.getMessage());
        log.info("***************异常结束***************");
        return new ApiResponse<>(e.getBaseCode(), e.getMessage(), null);
    }
}
